//
//  AppDelegate+UMSocial.m
//  LYouSubscribeApp
//
//  Created by grx on 2018/12/14.
//  Copyright © 2018年 grx. All rights reserved.
//

#import "AppDelegate+UMSocial.h"
#import "LJContactManager.h"

@implementation AppDelegate (UMSocial)

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        swizzleMethod(class, @selector(application:didFinishLaunchingWithOptions:),
                      @selector(LY_application:didFinishLaunchingWithOptions:));
    });
}
static inline void swizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector)   {
    Method originalMethod = class_getInstanceMethod(class, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
    BOOL didAddMethod =
    class_addMethod(class,
                    originalSelector,
                    method_getImplementation(swizzledMethod),
                    method_getTypeEncoding(swizzledMethod));
    if (didAddMethod) {
        class_replaceMethod(class,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
    } else {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    }
}

- (BOOL)LY_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    BOOL result = [self LY_application:application didFinishLaunchingWithOptions:launchOptions];
    /** 友盟统计 */
    [UMConfigure initWithAppkey:@"5c1a28f4f1f5569a8b000352" channel:@"App Store"];
    /*! 数据库 */
    [MagicalRecord setupCoreDataStackWithStoreNamed:@"LYouFavorVideoData.sqlite"];
    NSString* docs=[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)lastObject];
    /*! 数据库地址 */
    NSLog(@"docs======%@",docs);
    [LJContactManager sharedInstance].contactChangeHandler = ^{
        NSLog(@"通讯录修改咯");
    };
    
    return result;
}

@end
